#pragma once

#include <QtSql/QSqlQuery>

#include "exports.hpp"




namespace sql
{
	/**
	 * This class is a wrapper around QSqlQuery.
	 * It offers nearly the same functionality, but adds a much nicer error handling than
	 * qt does.
	 */
	class SQL_API query
	{
	private:

		QSqlQuery   m_query;

	public:

		/**
		 * Creates a query for the given database.
		 */
		query(QSqlDatabase database);

		/**
		 * Creates a query from the given string and for the given database.
		 */
		query(QString query_string, QSqlDatabase database);

		/**
		 * Destroys a query.
		 */
		virtual ~query();



		/**
		 * Prepares the sql statement.
		 */
		void prepare(QString query_string);

		/**
		 * Executes the prepared sql statement.
		 */
		void exec();

		/**
		 * Executes the prepared sql statement and returns weather it was executed successful or not.
		 */
		bool try_exec();

		/**
		 * @returns the last error of this query
		 */
		QSqlError lastError();
	};
	///////////////////////////////////////////////////////////////////////////////////////////////
}
///////////////////////////////////////////////////////////////////////////////////////////////////
